package com.offcn.dao.Impl;

import com.offcn.dao.BaseDao;
import com.offcn.dao.CourseUserDao;
import com.offcn.entity.Course;
import com.offcn.entity.CourseUser;
import com.offcn.utils.PageTool;

import java.util.List;

public class CourseUserDaoImpl extends BaseDao<CourseUser> implements CourseUserDao {
    @Override
    public int getTotalCount(String ids) {
        String sql = "select count(*) from course_user cu, user u where u.uid = cu.uid and cu.uid in " + ids;
        long o = (long) singleData(sql);
        return (int) o;
    }

    @Override
    public List<CourseUser> findByPage(PageTool pageTool, String ids) {
        String sql = "select * from course_user cu, course c, `user` u where" +
                " u.uid = cu.uid and c.cid = cu.cid and cu.uid in" + ids + " limit ?,?";
        return moreLine(sql, CourseUser.class, pageTool.getStartIndex(), pageTool.getPageSize());
    }

    @Override
    public int updateCourseUser(String id, String cid) {
        String sql = "update course_user set cid = ? where id = ?";
        return dml(sql, cid, id);
    }

    @Override
    public int delAll(String arr) {
        String sql = "delete from course_user where id in" + arr;
        return dml(sql);
    }
}
